package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.ItemVO;
import com.jt.vo.SysResult;
import com.sun.org.apache.bcel.internal.generic.FieldGenOrMethodGen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.swing.plaf.multi.MultiButtonUI;

@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;
    /**
     *  - 请求路径: http://localhost:8091/file/upload
     *  - 请求类型: post
     *  - 请求参数: file: 二进制的字节信息
     *  - 返回值:  SysResult对象(ImageVO)
     *  核心API:
     *       file.transferTo("图片的全路径");
     */
    @PostMapping("/upload")
        public SysResult upload(MultipartFile file){
        ImageVO imageVO=fileService.upload(file);
        if(imageVO==null){
            return SysResult.fail();
        }
        return SysResult.success(imageVO);
        }
        /**
         * 请求路径: http://localhost:8091/file/deleteFile
         * 请求类型: delete
         * 请求参数:*/
        @DeleteMapping("/deleteFile")
    public SysResult deleteFile(String virtualPath){
            fileService.deleteFile(virtualPath);
            return SysResult.success();
        }
}
